﻿namespace DimensionsHelper.LanguageService.Syntax;

// object[.. < options >].method
// object[.. < options >].property = expression
// <options> ::= [In categories]
public class ObjectCollectionIteration : Expression
{
    private readonly SyntaxToken _dotDotToken;
    private Identifier? _categoriesName;
    private SyntaxToken? _inKeywordToken;

    internal ObjectCollectionIteration(SyntaxNode? parent, SyntaxToken dotDotToken) :
        base(SyntaxKinds.ObjectCollectionIteration, parent)
    {
        SetChildField(ref _dotDotToken, dotDotToken);
    }


    public SyntaxToken DotDotToken => _dotDotToken;

    public SyntaxToken? InKeywordToken => _inKeywordToken;

    public Identifier? CategoriesName => _categoriesName;


    public ObjectCollectionIteration Update(SyntaxToken inKeywordToken, Identifier categoriesName)
    {
        SetChildNullableField(ref _inKeywordToken, SyntaxToken.IsNullOrEmpty, inKeywordToken);
        SetChildNullableField(ref _categoriesName, Identifier.IsDefaultOrEmpty, categoriesName);
        return this;
    }
}


public static partial class NodeFactory
{
    public static ObjectCollectionIteration CreateObjectCollectionIteration(SyntaxNode? parent,
        SyntaxToken dotDotToken, SyntaxToken inKeywordToken, Identifier categories)
    {
        ObjectCollectionIteration expr = new(parent, dotDotToken);
        return expr.Update(inKeywordToken, categories);
    }


    public static ObjectCollectionIteration CreateObjectCollectionIteration(SyntaxNode? parent,
        SyntaxToken dotDotToken)
    {
        return new ObjectCollectionIteration(parent, dotDotToken);
    }
}